package TCP2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Receive {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9090);
        Socket s = ss.accept();// 阻塞等待客户端连接等待客户端连接
        System.out.println("客户端已连接");
        InputStream is = s.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        int i=1;
        try {
            while (true) {
                System.out.println("这是收到的第" + i+"条消息：");
                i++;
                String message = dis.readUTF();
                System.out.println( message);
            }
        } catch (IOException e) {
            System.out.println("客户端已断开连接");
        } finally {
            dis.close();
            s.close();
            ss.close();
        }
    }
}
